package leetcode.code2483;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int bestClosingTime(String customers) {
		int len = customers.length();
		int[] y = new int[len + 1];
		for (int i = len - 1; i >= 0; i--) {
			y[i] = customers.charAt(i) == 'Y' ? y[i + 1] + 1 : y[i + 1];
		}
		int ans = Integer.MAX_VALUE, index = -1;
		for (int i = 0, n = 0; i < y.length; i++) {
			if (ans > y[i] + n) {
				ans = y[i] + n;
				index = i;
			}
			if (i < len)
				n += customers.charAt(i) == 'N' ? 1 : 0;
		}
		return index;
	}

	@Override
	public void debug4() {
		H.compare(2, this.bestClosingTime("YYNY"));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
